import sys
import time

from basic.config import GlobalCfg
from data.database import DBService
from modules.master import ModuleMaster
from web.web import Website


class Service():
    def __init__(self, config='config.json'):
        GlobalCfg.init(config)
        self.database = DBService()
        self.modules_master = ModuleMaster()
        self.website = Website(GlobalCfg.web_ip, GlobalCfg.web_port, self.modules_master.website_modules)
        
    def run(self):
        # 运行 module master
        self.modules_master.power_on()

        # 运行flask网站。将会pending在网站里。
        self.website.run()


if __name__ == '__main__':
    if len(sys.argv) < 2:
        print('缺少配置文件')
        exit(0)

    Service(sys.argv[1]).run()
    
    